package jpmolconfig;


import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import jpmolconfig.nonBondedSwitches;

/*
 * configJPanel.java
 *
 * Created on March 21, 2009, 11:43 AM
 */



/**
 *
 * @author  Chris
 */
public class configJPanel extends javax.swing.JPanel {

    /** Creates new form configJPanel */
    public configJPanel() {
        initComponents();
        
        OSname = System.getProperty("os.name");
        System.out.println( OSname );
        if(OSname.indexOf("Windows") != -1) notWindows = false;
        else notWindows = true;

        //find current folder
        File dir1 = new File (".");

        try {
            mainFolder = dir1.getCanonicalPath();
        } catch (IOException e) {
            mainFolder = ".";
        }
        
        if(!notWindows) autoConfStr = mainFolder + "\\auto.conf";
        else autoConfStr = mainFolder + "/auto.conf";

        jTextField1.setText(mainFolder);

        loadConf( true );
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jButton3 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jTextField5 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField1 = new javax.swing.JTextField();
        jButton7 = new javax.swing.JButton();
        jButton12 = new javax.swing.JButton();
        jButton14 = new javax.swing.JButton();
        jTextField11 = new javax.swing.JTextField();
        jTextField12 = new javax.swing.JTextField();
        jCheckBox12 = new javax.swing.JCheckBox();
        jPanel8 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jTextField6 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextField7 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextField8 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jCheckBox9 = new javax.swing.JCheckBox();
        jCheckBox10 = new javax.swing.JCheckBox();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jTextField9 = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jCheckBox11 = new javax.swing.JCheckBox();
        jPanel2 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jCheckBox2 = new javax.swing.JCheckBox();
        jCheckBox3 = new javax.swing.JCheckBox();
        jCheckBox8 = new javax.swing.JCheckBox();
        jPanel6 = new javax.swing.JPanel();
        jCheckBox4 = new javax.swing.JCheckBox();
        jCheckBox5 = new javax.swing.JCheckBox();
        jCheckBox6 = new javax.swing.JCheckBox();
        jCheckBox7 = new javax.swing.JCheckBox();
        jButton9 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jPanel7 = new javax.swing.JPanel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jRadioButton4 = new javax.swing.JRadioButton();
        jTextField10 = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();

        jPanel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jButton3.setText("Select directory");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton2.setText("Position file");
        jButton2.setMaximumSize(new java.awt.Dimension(107, 23));
        jButton2.setMinimumSize(new java.awt.Dimension(107, 23));
        jButton2.setPreferredSize(new java.awt.Dimension(107, 23));
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton6.setText("Velocity file");
        jButton6.setDoubleBuffered(true);
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton4.setText("PSF file");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("PAR file");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton7.setText("Create conf");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton12.setText("Topology");
        jButton12.setEnabled(false);
        jButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton12ActionPerformed(evt);
            }
        });

        jButton14.setText("Include Directory");
        jButton14.setEnabled(false);
        jButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton14ActionPerformed(evt);
            }
        });

        jTextField11.setEnabled(false);

        jTextField12.setEnabled(false);

        jCheckBox12.setText("GROMACS/AMBER");
        jCheckBox12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox12ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jButton14, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton12, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                    .addComponent(jButton4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE)
                    .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE)
                    .addComponent(jTextField4, javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE)
                    .addComponent(jTextField5, javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE)
                    .addComponent(jTextField11, javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE)
                    .addComponent(jTextField12, javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jCheckBox12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton3)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCheckBox12))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton12)
                    .addComponent(jTextField11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton14)
                    .addComponent(jTextField12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton7))
                .addContainerGap(23, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Input file selection", jPanel1);

        jLabel3.setText("Simulation temperature");

        jTextField6.setText("300");
        jTextField6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField6ActionPerformed(evt);
            }
        });

        jLabel4.setText("Number of steps");

        jTextField7.setText("10000");
        jTextField7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField7ActionPerformed(evt);
            }
        });

        jLabel5.setText("Step size");

        jTextField8.setText("1");
        jTextField8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField8ActionPerformed(evt);
            }
        });

        jLabel6.setText("°K      (Press Enter to update)");

        jLabel7.setText("fs       (Press Enter to update)");

        jCheckBox9.setText("Periodic boundary conditions");

        jCheckBox10.setText("Generate DCD file");

        jLabel8.setText("          (Press Enter to update)");

        jLabel9.setText("Damping ");

        jTextField9.setText("80");
        jTextField9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField9ActionPerformed(evt);
            }
        });

        jLabel10.setText("1/ps   (Press Enter to update)");

        jCheckBox11.setText("Generate final position/velociy files");

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCheckBox11)
                    .addComponent(jCheckBox10)
                    .addComponent(jCheckBox9)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel9))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextField9, 0, 0, Short.MAX_VALUE)
                            .addComponent(jTextField8)
                            .addComponent(jTextField7)
                            .addComponent(jTextField6, javax.swing.GroupLayout.DEFAULT_SIZE, 52, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10)
                            .addComponent(jLabel8)
                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))))
                .addContainerGap(134, Short.MAX_VALUE))
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9)
                            .addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jCheckBox9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCheckBox10))
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCheckBox11)
                .addGap(148, 148, 148))
        );

        jTabbedPane1.addTab("General settings", jPanel8);

        jPanel2.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Bonded"));

        jCheckBox1.setSelected(true);
        jCheckBox1.setText("Bonds");
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        jCheckBox2.setSelected(true);
        jCheckBox2.setText("Angles");

        jCheckBox3.setSelected(true);
        jCheckBox3.setText("Dihedrals");

        jCheckBox8.setSelected(true);
        jCheckBox8.setText("Impropers");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCheckBox1)
                    .addComponent(jCheckBox2)
                    .addComponent(jCheckBox3)
                    .addComponent(jCheckBox8))
                .addContainerGap(40, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jCheckBox1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jCheckBox2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jCheckBox3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jCheckBox8)
                .addContainerGap(78, Short.MAX_VALUE))
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Non-bonded"));

        jCheckBox4.setSelected(true);
        jCheckBox4.setText("Lennard Jones");

        jCheckBox5.setSelected(true);
        jCheckBox5.setText("Coulomb");

        jCheckBox6.setText("Coulomb Dielec");

        jCheckBox7.setText("Implicit solvent");

        jButton9.setText("advanced settings");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        jButton10.setText("advanced settings");
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });

        jButton11.setText("advanced settings");
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCheckBox4)
                            .addComponent(jCheckBox6)
                            .addComponent(jCheckBox5))
                        .addGap(10, 10, 10)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButton11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addComponent(jCheckBox7))
                .addContainerGap(68, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckBox4)
                    .addComponent(jButton9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckBox5)
                    .addComponent(jButton10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckBox6)
                    .addComponent(jButton11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jCheckBox7)
                .addContainerGap(68, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(25, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Force field", jPanel2);

        jPanel7.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        buttonGroup1.add(jRadioButton1);
        jRadioButton1.setSelected(true);
        jRadioButton1.setText("Langevin thermostat (NVT ensemble)");

        buttonGroup1.add(jRadioButton2);
        jRadioButton2.setText("Verlet/Leapfrog (NVE ensemble)");

        buttonGroup1.add(jRadioButton3);
        jRadioButton3.setText("Normal Mode Langevin (NVT ensemble)");
        jRadioButton3.setEnabled(false);

        buttonGroup1.add(jRadioButton4);
        jRadioButton4.setText("Recursive Multiple Thermostats (NVT  ensemble)");

        jTextField10.setText("0.3");
        jTextField10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField10ActionPerformed(evt);
            }
        });

        jLabel11.setText("Nose mass");

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jRadioButton2)
                    .addComponent(jRadioButton1)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(jRadioButton4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel11)
                        .addGap(10, 10, 10)
                        .addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jRadioButton3))
                .addContainerGap(101, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jRadioButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButton4)
                    .addComponent(jLabel11)
                    .addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButton3)
                .addContainerGap(131, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Integrators", jPanel7);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 499, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 499, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 276, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 265, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
    }// </editor-fold>//GEN-END:initComponents

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
        //get main directory name
        File posFile;
        JFileChooser chooser = new JFileChooser(mainFolder);
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setDialogTitle("Select Main Folder");
        int result = chooser.showSaveDialog(this);
        if(result == JFileChooser.APPROVE_OPTION){
            posFile = chooser.getSelectedFile();
            mainFolder = chooser.getSelectedFile().getAbsolutePath();//chooser.getCurrentDirectory()+"\\"+chooser.getName(posFile);
            jTextField1.setText(mainFolder);
            //jTextArea1.append(mainFolder+", ");
            if(!notWindows) autoConfStr = mainFolder + "\\auto.conf";
            else autoConfStr = mainFolder + "/auto.conf";
            //load old conf if available
            if(!loadConf( true )){
                pos[1] = vel[1] = par[1] = psf[1] = top[1] = "";
                jTextField2.setText("");
                jTextField3.setText("");
                jTextField4.setText("");
                jTextField5.setText("");
                jTextField11.setText("");
            }
        }else{
            if(result != JFileChooser.CANCEL_OPTION)
                JOptionPane.showMessageDialog(this, "Error selecting folder.");
        }
}//GEN-LAST:event_jButton3ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
        pos = findFiles("Select Position File");
        jTextField2.setText(pos[1]);
        //jTextArea1.append(pos[1]+", ");
}//GEN-LAST:event_jButton2ActionPerformed

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
// TODO add your handling code here:
        vel = findFiles("Select Velocity File");
        jTextField3.setText(vel[1]);
        //jTextArea1.append(vel[1]+", ");
}//GEN-LAST:event_jButton6ActionPerformed

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
// TODO add your handling code here:
        psf = findFiles("Select PSF File");
        jTextField4.setText(psf[1]);
        //jTextArea1.append(psf[1]+", ");
}//GEN-LAST:event_jButton4ActionPerformed

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
// TODO add your handling code here:
        par = findFiles("Select PAR File");
        jTextField5.setText(par[1]);
        //jTextArea1.append(par[1]+", ");
}//GEN-LAST:event_jButton5ActionPerformed

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
// TODO add your handling code here:
        String [] tmp = new String[3];
        tmp = findFiles("Save configuration file");
        if(!tmp[1].equals("")){
            createConf(tmp[2]);
            loadConf( false );  //print to box
        }
}//GEN-LAST:event_jButton7ActionPerformed

private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed
// TODO add your handling code here:
    top = findFiles("Select Toplogy File");
    jTextField11.setText(top[1]);
    //jTextArea1.append(top[1]+", ");
}//GEN-LAST:event_jButton12ActionPerformed

private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton14ActionPerformed
// TODO add your handling code here:
        //get main directory name
        File posFile;
        JFileChooser chooser = new JFileChooser(topFolder);
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setDialogTitle("Select Topology Folder");
        int result = chooser.showSaveDialog(this);
        if(result == JFileChooser.APPROVE_OPTION){
            posFile = chooser.getSelectedFile();
            topFolder = chooser.getSelectedFile().getAbsolutePath();
            jTextField12.setText(topFolder);
            //jTextArea1.append(topFolder+", ");
        }else{
            if(result != JFileChooser.CANCEL_OPTION)
                JOptionPane.showMessageDialog(this, "Error selecting folder.");
        }
}//GEN-LAST:event_jButton14ActionPerformed

private void jCheckBox12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox12ActionPerformed
// TODO add your handling code here:
    if(jCheckBox12.isSelected()){
        jButton12.setEnabled(true);
        jButton14.setEnabled(true);
        jButton4.setEnabled(false);
        jButton5.setEnabled(false);
        jTextField11.setEnabled(true);
        jTextField12.setEnabled(true);
        jTextField4.setEnabled(false);
        jTextField5.setEnabled(false);
    }else{
        jButton12.setEnabled(false);
        jButton14.setEnabled(false);
        jButton4.setEnabled(true);
        jButton5.setEnabled(true);
        jTextField11.setEnabled(false);
        jTextField12.setEnabled(false);
        jTextField4.setEnabled(true);
        jTextField5.setEnabled(true);

    }
}//GEN-LAST:event_jCheckBox12ActionPerformed

private void jTextField6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField6ActionPerformed
// TODO add your handling code here:
        float temp = 200;
        try {
            temp = Float.valueOf(jTextField6.getText());
        } catch(NumberFormatException e) {
            System.out.println(e.getMessage());
            temp = -1;
        }
        if(temp > 0) simTemp = temp;
}//GEN-LAST:event_jTextField6ActionPerformed

private void jTextField7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField7ActionPerformed
// TODO add your handling code here:
        int temp = 200;
        try {
            temp = Integer.valueOf(jTextField7.getText());
        } catch(NumberFormatException e) {
            System.out.println(e.getMessage());
            temp = -1;
        }
        if(temp > 0) totalStepNumber = temp;
}//GEN-LAST:event_jTextField7ActionPerformed

private void jTextField8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField8ActionPerformed
// TODO add your handling code here:
        float temp = 1;
        try {
            temp = Float.valueOf(jTextField8.getText());
        } catch(NumberFormatException e) {
            System.out.println(e.getMessage());
            temp = -1;
        }
        if(temp > 0) stepSize = temp;
}//GEN-LAST:event_jTextField8ActionPerformed

private void jTextField9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField9ActionPerformed
// TODO add your handling code here:
        float temp = 80;
        try {
            temp = Float.valueOf(jTextField9.getText());
        } catch(NumberFormatException e) {
            System.out.println(e.getMessage());
            temp = -1;
        }
        if(temp > 0) dampingCoeff = temp;
}//GEN-LAST:event_jTextField9ActionPerformed

private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jCheckBox1ActionPerformed

private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
// TODO add your handling code here:
        nonBondedSwitches nbs = new nonBondedSwitches(null,true);
        nbs.setVisible(true);
        //modal so will wait here for user to set invisible
        if(nbs.str.length() > 0 && !nbs.str.equals("")){
            LJSwitch = nbs.str;
        }
        nbs.dispose();
        //jTextArea1.setText(LJSwitch);
}//GEN-LAST:event_jButton9ActionPerformed

private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
// TODO add your handling code here:
            nonBondedSwitches nbs = new nonBondedSwitches(null,true);
        nbs.setVisible(true);
        //modal so will wait here for user to set invisible
        if(nbs.str.length() > 0 && !nbs.str.equals("")){
            CoulombSwitch = nbs.str;
        }
        nbs.dispose();
        //jTextArea1.setText(CoulombSwitch);
}//GEN-LAST:event_jButton10ActionPerformed

private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
// TODO add your handling code here:
        nonBondedSwitches nbs = new nonBondedSwitches(null,true);
        nbs.setVisible(true);
        //modal so will wait here for user to set invisible
        if(nbs.str.length() > 0 && !nbs.str.equals("")){
            CoulombSwitch = nbs.str;
        }
        nbs.dispose();
        //jTextArea1.setText(CoulombSwitch);
}//GEN-LAST:event_jButton11ActionPerformed

private void jTextField10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField10ActionPerformed
// TODO add your handling code here:
        float temp = 0.3f;
        try {
            temp = Float.valueOf(jTextField10.getText());
        } catch(NumberFormatException e) {
            System.out.println(e.getMessage());
            temp = -1;
        }
        if(temp > 0) noseMass = temp;
}//GEN-LAST:event_jTextField10ActionPerformed

    private String [] findFiles(String fileDescription) {
        //get file name
        File posFile;
        String [] fileData = new String[3];

        final JFileChooser chooser = new JFileChooser(mainFolder);
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        //Windows crazy paths dont work! All for now
        if(true) { //!notWindows) {
            chooser.setAcceptAllFileFilterUsed(false);  
            chooser.setFileFilter(new RestrictedFilter());  
            final File defaultFolder = chooser.getCurrentDirectory();  
            chooser.addPropertyChangeListener(JFileChooser.DIRECTORY_CHANGED_PROPERTY,  
                                                  new PropertyChangeListener()  
            {  
                public void propertyChange(PropertyChangeEvent e)  
                {  
                    File currentFolder = (File)e.getNewValue();  
                    if(!currentFolder.equals(defaultFolder))  
                        chooser.setCurrentDirectory(defaultFolder);  
                }  
            });  
           
        }

        chooser.setDialogTitle(fileDescription);
        int result = chooser.showSaveDialog(this);
        if(result == JFileChooser.APPROVE_OPTION){
            posFile = chooser.getSelectedFile();
            fileData[0] = chooser.getCurrentDirectory()+"";
            //if( (chooser.getCurrentDirectory()+"").equals(mainFolder)){
            fileData[1] = chooser.getName(posFile);
            fileData[2] =  chooser.getSelectedFile().getAbsolutePath();
            System.out.println( fileData[2] );

        }else{
            if(result != JFileChooser.CANCEL_OPTION)
                JOptionPane.showMessageDialog(this, "Selection Error!");
            fileData[0] = ""; fileData[1] = ""; fileData[2] = "";
        }
        return fileData;
    }


    public boolean createConf(String fname) {

        if(pos[1].length() == 0 || 
                (!jCheckBox12.isSelected() && (par[1].length() == 0 || psf[1].length() == 0)) ||
                (jCheckBox12.isSelected() && top[1].length() == 0)
                    ){
            JOptionPane.showMessageDialog(this, "Require position and PAR/PSF or TOP files!");
            return false;
        }

        //default to auto.conf
        if(fname.equals("")) fname = autoConfStr;
        
        try{
            FileWriter fileWriter = new FileWriter(fname,false);//"auto.conf",false); //(mainFolder + "\\auto.conf"false for not append
            BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);

            //header
            Date now = new Date();
            bufferedWriter.write("#\n# Generated by JProtomol on "+now.toString()+"\n#\n\n");
            //sim data
            bufferedWriter.write("firststep 0\nnumsteps "+String.valueOf(totalStepNumber)+"\n");
            int ofreq = totalStepNumber/10000;
            if(ofreq < 1) ofreq = 1;
            bufferedWriter.write("outputfreq "+String.valueOf(ofreq)+"\n");
            bufferedWriter.write("exclude scaled1-4\n");
            bufferedWriter.write("GUI true\nGUIPort 52753\n\n");
            //input files
            if(pos[0].equals(mainFolder) || mainFolder.equals(".") )
                bufferedWriter.write("posfile "+pos[1]+"\n");
            else
                bufferedWriter.write("posfile "+pos[2]+"\n");

            if(vel[1].length() > 0)
                bufferedWriter.write("velfile "+vel[1]+"\n");
            else
                bufferedWriter.write("temperature "+String.valueOf(simTemp)+"\n");

            if(jCheckBox12.isSelected()) {
                bufferedWriter.write("gromacstopologyfile "+top[1]+"\n");
                bufferedWriter.write("gromacsparameterpath "+topFolder+"\n");
            }else{
                bufferedWriter.write("psffile "+psf[1]+"\n");
                bufferedWriter.write("parfile "+par[1]+"\n\n");
            }

            if(jCheckBox6.isSelected() || jCheckBox7.isSelected()) 
                bufferedWriter.write("scpismfile scpismQuartic.inp\n\n");

            //
            if(jCheckBox9.isSelected()) {
                bufferedWriter.write("boundaryConditions periodic\n");
            }else {
                bufferedWriter.write("boundaryConditions vacuum\n");
            }
            bufferedWriter.write("cellManager Cubic\ncellsize 5\n\n");
            //Output files
            if(jCheckBox10.isSelected()) bufferedWriter.write("dcdfile auto.out.dcd\n");
            if(jCheckBox11.isSelected()) bufferedWriter.write("finXYZPosFile auto.out.pos.xyz\nfinXYZVelFile auto.out.vel.xyz\n");
            bufferedWriter.write("allenergiesfile auto.out.energy\n\n");

            //Integrators
            if(jRadioButton1.isSelected()) bufferedWriter.write("Integrator {\n  level 0 LangevinLeapfrog {\n    timestep "+String.valueOf(stepSize)+"\n    temperature "+String.valueOf(simTemp)+"\n    gamma "+dampingCoeff+"\n\n");
            if(jRadioButton2.isSelected()) bufferedWriter.write("Integrator {\n  level 0 Leapfrog {\n    timestep "+String.valueOf(stepSize)+"\n\n");
            if(jRadioButton4.isSelected()) bufferedWriter.write("Integrator {\n  level 0 RMT {\n    timestep "+String.valueOf(stepSize)+"\n    temperature "+String.valueOf(simTemp)+"\n    NumStats 1\n    Q1 "+String.valueOf(noseMass)+"\n\n");
            //Forces
            if(jCheckBox1.isSelected()) bufferedWriter.write("    force Bond\n");
            if(jCheckBox2.isSelected()) bufferedWriter.write("    force Angle\n");
            if(jCheckBox3.isSelected()){
                if(jCheckBox12.isSelected()) bufferedWriter.write("    force RBDihedral\n");
                else bufferedWriter.write("    force Dihedral\n");
            }
            if(jCheckBox8.isSelected() && !jCheckBox12.isSelected())
                bufferedWriter.write("    force Improper\n");
            //if(jCheckBox4.isSelected()) bufferedWriter.write("    force LennardJones\n      -algorithm NonbondedSimpleFull\n");
            if(jCheckBox4.isSelected()) bufferedWriter.write("    force LennardJones\n"+LJSwitch);
            if(jCheckBox5.isSelected()) bufferedWriter.write("    force Coulomb\n"+CoulombSwitch);
            if(jCheckBox6.isSelected()) bufferedWriter.write("    force CoulombSCPISM\n"+CoulombSwitch+"      -D "+dampingCoeff+"\n");
            if(jCheckBox7.isSelected()){
                bufferedWriter.write("    force BornRadii\n      -algorithm NonbondedCutoff\n      -switchingFunction Cutoff\n      -bornswitch 3\n      -cutoff 5\n      -cutoff 5\n");
                bufferedWriter.write("    force BornSelf\n      -algorithm NonbondedCutoff\n      -switchingFunction Cutoff\n      -bornswitch 3\n      -cutoff 5\n      -cutoff 5\n      -D "+dampingCoeff+"\n");
            }
            
            //end
            bufferedWriter.write("  }  \n}\n");
            //bufferedWriter.write(""); bufferedWriter.newLine();
            //
            bufferedWriter.close();
            return true;
        }catch(IOException ew){
            JOptionPane.showMessageDialog(this, "Cannot output conf file!");
            return false;
        }

    }

    public boolean loadConf( boolean siftData ) {

        try {
            BufferedReader in
                = new BufferedReader(new FileReader(autoConfStr));//"auto.conf"));
            //File dir1 = new File (".");
            //mainFolder = dir1.getCanonicalPath();
            //jTextField1.setText(mainFolder);
            vel[0] = vel[1] = vel[2] = "";
            float ret;

            //if(!siftData) jTextArea1.setText(""); //clear if not sifting
            
            while (in.ready()) {
                String line = in.readLine();
                String[] tmp = {"","",""};

                if(siftData){
                    //filenames
                    if(findKeyword(line, "posfile",pos))
                        jTextField2.setText(pos[1]);
                    else if(findKeyword(line, "velfile",vel))
                        jTextField3.setText(vel[1]);
                    else if(findKeyword(line, "psffile",psf)){
                        jTextField4.setText(psf[1]);
                        jCheckBox12.setSelected(false);
                    }else if(findKeyword(line, "parfile",par)){
                        jTextField5.setText(par[1]);
                        jCheckBox12.setSelected(false);
                    }else if(findKeyword(line, "gromacstopologyfile",top)){
                        jTextField11.setText(top[1]);
                        jCheckBox12.setSelected(true);
                    }else if(findKeyword(line, "gromacsparameterpath",tmp)){
                        topFolder = tmp[1];
                        jTextField12.setText(topFolder);
                        jCheckBox12.setSelected(true);
                    }
                    jCheckBox12ActionPerformed(null);
                    //other values
                    if((ret = findKeywordValue(line,"numsteps")) >= 0.0f){
                        totalStepNumber = (int)ret;
                        jTextField7.setText(String.valueOf(totalStepNumber));
                    } 
                    if((ret = findKeywordValue(line,"gamma")) >= 0.0f){
                        dampingCoeff = ret;
                        jTextField9.setText(String.valueOf(dampingCoeff));
                    } 
                    if((ret = findKeywordValue(line,"timestep")) >= 0.0f){
                        stepSize = ret;
                        jTextField8.setText(String.valueOf(stepSize));
                    } 
                    if((ret = findKeywordValue(line,"temperature")) >= 0.0f){
                        simTemp = ret;
                        jTextField6.setText(String.valueOf(simTemp));
                    } 
                    if((ret = findKeywordValue(line,"Q1")) >= 0.0f){
                        noseMass = ret;
                        jTextField10.setText(String.valueOf(noseMass));
                    } 
                } else{
                   // jTextArea1.append(line+"\n");
                }
            }

            // dispose all the resources after using them.
            in.close();
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }

    }

    private float findKeywordValue(String line, String keyToFind) {
        int index;
        float ret = -1;
        if( (index = line.indexOf(keyToFind)) != -1) {
            String tmp = line.substring(index+keyToFind.length()+1,line.length());
            try{
                ret = Float.valueOf(tmp);
            } catch (Exception e) {
                ret = -1;
            }
            return ret;
        }else{
            return ret;
        }
        
    }
    
    private boolean findKeyword(String line, String keyToFind, String [] inp) {
        //String [] dat = new String[3];

        int index;
        if( (index = line.indexOf(keyToFind)) != -1) {
            inp[1] = line.substring(index+keyToFind.length()+1,line.length());
            inp[0] = mainFolder; inp[2] = inp[1];
            return true;
        }else{
            return false;
        }

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton9;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox10;
    private javax.swing.JCheckBox jCheckBox11;
    private javax.swing.JCheckBox jCheckBox12;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JCheckBox jCheckBox3;
    private javax.swing.JCheckBox jCheckBox4;
    private javax.swing.JCheckBox jCheckBox5;
    private javax.swing.JCheckBox jCheckBox6;
    private javax.swing.JCheckBox jCheckBox7;
    private javax.swing.JCheckBox jCheckBox8;
    private javax.swing.JCheckBox jCheckBox9;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField10;
    private javax.swing.JTextField jTextField11;
    private javax.swing.JTextField jTextField12;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    private javax.swing.JTextField jTextField9;
    // End of variables declaration//GEN-END:variables
    //My variables
    public String mainFolder=".", autoConfStr = "auto.conf", topFolder = ".";
    public String[] pos = {"","",""}, vel = {"","",""}, par = {"","",""}, psf = {"","",""};
    public String[] top = {"","",""};
    public String OSname;
    public boolean notWindows;
    public int currentStepNumber, totalStepNumber=10000;
    //public JMolecularViewer jmv;
    public float simTemp=300.0f, stepSize = 1.0f;
    public boolean pmolCanRun=true;
    public String LJSwitch = "      -algorithm NonbondedCutoff\n      -switchingFunction C2\n      -switchon 6.0\n      -cutoff 9.0\n";
    public String CoulombSwitch = "      -algorithm NonbondedCutoff\n      -switchingFunction C1\n      -switchon 0.0\n      -cutoff 12.0\n";
    public float dampingCoeff = 80;
    public float noseMass = 0.3f;
    //end my variables

}
